package cc.wsyw126.java.nowcoder.ali;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack;

/**
 * Created by Administrator on 2017/4/26.
 */
public class two {
    public static void main(String[] args) {

        ArrayList<Integer> inputs = new ArrayList<Integer>();
        Scanner in = new Scanner(System.in);
        String line = in.nextLine();
        if(line != null && !line.isEmpty()) {
            int res = 0;
            try {
                res = resolve(line.trim());
            } catch (Exception e) {
                res = -1;
            }
            System.out.println(String.valueOf(res));
        }
    }

    // write your code here
    public static int resolve(String expr) {
        Stack<Integer> integerStack = new Stack<Integer>();
        String[] split = expr.split(" ");
        for (int i = 0; i < split.length; i++) {
            if (split[i].equals("^")) {
                Integer pop = integerStack.pop();
                pop++;
                integerStack.push(pop);
            } else if (split[i].equals("+")){
                Integer pop = integerStack.pop();
                Integer pop1 = integerStack.pop();
                integerStack.push(pop+pop1);
            }else if (split[i].equals("-")){
                Integer pop = integerStack.pop();
                Integer pop1 = integerStack.pop();
                integerStack.push(pop1-pop);
            } else {
                integerStack.push(Integer.valueOf(split[i]));
            }
        }
        return integerStack.pop();
    }
}
